﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/06/10
 * 
 * 功能说明：打包上传
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Whir_System_Module_Template_TemplateManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //上传
    protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        string fileName = this.FileUpload1.PostedFile.FileName;
        if (fileName != null && fileName != "")
        {
            try
            {
                string lastName = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();      //文件后缀名

                if (lastName == "rar" || lastName == "zip")       //判断类型(压缩文件)
                {
                    if (this.FileUpload1.PostedFile.ContentLength < 10240000)
                    {
                        string name = DateTime.Now.ToString().Replace(":","");
                        this.hf1.Value = Server.MapPath(Whir.Common.Settings.GetString("SystemPath") + "Temp/" + name + "." + lastName);

                        this.FileUpload1.PostedFile.SaveAs(this.hf1.Value);
                    }
                    else
                    {
                        Whir.Common.WebHelper.JsHelper.redirect(Page, "文件大小不可超过10m，上传失败！", "TemplateManage.aspx");
                        return;
                    }
                }
                else
                {
                    Whir.Common.WebHelper.JsHelper.redirect(Page, "只允许上传压缩文件 rar、zip，上传失败！", "TemplateManage.aspx");
                    return;
                }
            }
            catch (Exception er)
            {
                throw new Exception(er.Message);
            }
        }
        else
        {
            Whir.Common.WebHelper.JsHelper.redirect(Page, "请选择文件！", "TemplateManage.aspx");
        }
    }

    //解压
    protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        string dir = this.TextBox1.Text.Trim();
        if (dir != "")
            dir = "/" + dir;

        //解压
        Whir.Common.CompressionHelper.Decompress(this.hf1.Value, Server.MapPath(Whir.Common.Settings.GetString("SystemPath") + "Whir_System/file" + dir));

        //删除临时压缩包
        FileSystemObject.DeleteFile(this.hf1.Value);

        OLAdd();
    }

    //操作日志
    protected void OLAdd()
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = "上传并解压模板包";
        model.operateType = 1;
        model.operateResult = true;
        model.operateDesc = "";
        model.operateUrl = "Module/Template/TemplateList.aspx";

        Whir.Log.OperateLog.Add(model);
    }
}
